package com.itheima.controller;

import com.itheima.dto.TotalCityDTO;
import com.itheima.entity.Cities;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.service.ICitiesService;

import java.util.List;

/**
* cities 相关api
* @author Wei
* @since 2021-8-6 15:43:51
*/
@RestController
@RequestMapping("/cities")
public class CitiesController{

@Autowired
private ICitiesService citiesService;
        @GetMapping("/cityList")
    public ResponseEntity<TotalCityDTO> getAllCity(){
            try {
                TotalCityDTO dto = citiesService.getAllCity();
                return ResponseEntity.ok(dto);
            }catch (Exception e){
                e.printStackTrace();
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }

        }
        @GetMapping("/allcity")
    public ResponseEntity getAll(){
            try {
                List<Cities> cities = citiesService.getCities();
                return ResponseEntity.ok(cities);
            }catch (Exception e){
                e.printStackTrace();
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }
        }


}